<?php

namespace Biz\service\Userpenalty;

use Doraemon\cache\Queue;
use Doraemon\model\AdmBestUser;
use Doraemon\model\AdmOperateLog;
use Doraemon\model\AdmRecommendUser;
use Doraemon\model\Member;

class Forbidden
{

    public static function handle( $data = [])
    {
        $uid = $data['uid'];
        if(empty($uid)) return false;
        $admin_id = $data['admin_id'];
        $admin_name = $data['admin_name'];
        //处理封禁逻辑
        //删除用户在推荐表的数据
        AdmRecommendUser::deleteByUid($uid);
        //删除精华表数据
        AdmBestUser::deleteByUid($uid);
        //将用户的状态设置为冻结
        $member_data['status'] = Member::STATUS_BLOCKED;
        $rst = Member::updateUserInfo($uid, $member_data);
        if ($rst) {
            Queue::insertQueue('User/force_out_user', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            Queue::insertQueue('User/deleteSearch', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            Queue::insertQueue('User/delTokenCache', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            Queue::insertQueue('User/delUserinfoCache', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            Queue::insertQueue('DataUserProfile/delete', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            AdmOperateLog::addLog($uid, AdmOperateLog::$operate_type['ban_user'], $admin_id, $admin_name);
            return true;
        } else {
            return false;
        }

    }

    //解除封禁
    public static function cancle($data )
    {
        $uid = $data['uid'];
        if(empty($uid)) return false;
        $admin_id = $data['admin_id'];
        $admin_name = $data['admin_name'];
        $user_data['status'] = Member::STATUS_NORMAL;
        $rst = Member::updateUserInfo($uid,$user_data);
        if ($rst){
            $user_info = Member::getUserInfo($uid);
            $nick = $user_info['nick'];
            $mytype = $user_info['type'];
            Queue::insertQueue('User/addSearch', array(
                'uid' => $uid,
                'nick' => $nick,
                'type' => $mytype,
            ), Queue::QUEUE_COMMON);
            //删除cahce里面的缓存数据
            Queue::insertQueue('User/delUserinfoCache', array(
                'uid' => $uid,
            ), Queue::QUEUE_COMMON);
            AdmOperateLog::addLog($uid,AdmOperateLog::$operate_type['cancel_ban_user'],$admin_id,$admin_name);
            return true;
        }else{
            return false;
        }

    }





}
